<extend name="Public/base" />

<block name="body">
 
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>用户列表</h2>
	</div>
	<div class="" style="display: block;">
	<form name="scanfrm" class="search-form" action="{:U('user/alloc')}" method="post">
                	<div class="row">
                		<label>注册时间：</label>
                		<input type="text" id="time-start" name="time-start" class="text input-2x" value="" placeholder="起始时间"> -
                		<input type="text" id="time-end" name="time-end" class="text input-2x" value="" placeholder="结束时间">
                		<label>学生姓名：</label>
						<input type="text"   name="fullname" id="fullname" class="text input-2x" value=""  />
						<label>手机号：</label>
						<input type="text"   name="telephone" id="telephone" class="text input-2x" value=""  />
                	 	
                	 	<if condition="IS_ROOT != false">

                			<label>类型：</label>		 
	                		{$query_select_role_member}
                		</if>
                	</div>
			<div class="row">
						<if condition="IS_ROOT != false">
                			<label>活动类型：</label>	
                			<select name="active_type" class="active_type">
                				<option value="">全部</option>
                				<foreach name="select_active_type" item="item" key="key">
									<option value="{$key}">{$item}</option>
                				</foreach>
                			</select>	 
                		</if>

                	</div>

        <div class="row">
            <input type="submit" class="sch-btn" value="查 询" />
            &nbsp;&nbsp;&nbsp;<input type="button" class="sch-btn reset-btn" value="重置信息"  />
        </div>
    </form>
    </div>
	<form  action="{:U('user/saveAlloc')}" method="post" id="AllocFrm">
	
    <!-- 数据列表 -->
    <div class="data-table table-striped"  >
	<table class="">
    <thead>
        <tr>
		<th class="row-selected row-selected"><input class="check-all" type="checkbox"  /></th>
		<th class="">UID</th>
		<th class="">姓名</th>
		<th class="">年级</th>
		<th class="">年龄</th>
		<th class="">联系电话</th>
		<th class="">注册时间</th>
		<th class="">来源</th>
		<th class="">内部人员</th>
		</tr>
    </thead>
    <tbody>
   
		<volist name="_list" id="vo">
		<tr>
            <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" />  </td>
			<td>{$vo.id} </td>
			<td>{$vo.fullname}</td>
			<td>{$vo.grade_name}</td>
			<td>{$vo.generation_name}</td>
			<td><span>{$vo.telephone}</span></td>
			<td><span>{$vo.registered_time|date="Y-m-d H:i",###}</span></td>	 		 
		 
			<td>
				<foreach name="vo.bindList" item="vo2" >
					<?php if (substr($key, 0, 1 )==1) { ?>
					<span class="bind bind{$key}">
									<if condition="$key eq 11">地推</if>
										<if condition="$key eq 12">商户</if>
										<if condition="$key eq 13">客户经理</if>
										 
					*{$vo2.nickname}<em item="'bind_id':{$vo2.bind_id},'studen_id':'{$vo.id}'">X</em></span>	
					<?php } ?>
				</foreach>
				 
			</td> 		 
			<td>
				<foreach name="vo.bindList" item="vo2" >
					<?php if (substr($key, 0, 1 )==2) { ?>
					<span class="bind bind{$key}">
							<if condition="$key eq 21">课程顾问</if>
							<if condition="$key eq 22">老师</if>
							<if condition="$key eq 23">助理</if>
							<if condition="$key eq 24">教务</if>
							<if condition="$key eq 25">市场</if>
					*{$vo2.nickname}<em item="'bind_id':{$vo2.bind_id},'studen_id':'{$vo.id}'">X</em></span>	
					<?php } ?>
				</foreach>
				 
			</td> 	 
			 
		</tr>
		</volist>
	
	</tbody>
    </table> 
	</div>
	<div class="cf" style="padding-top: 20px;">
        <if condition="IS_ROOT != false">
                			<label>绑定到：</label>	
							{$alloc_select_role_member}
                		</if>
		 
            <input type="button" class="btn action-alloc"  value="分配" /> 
        	&nbsp;&nbsp;
			<!-- <input type="button" class="btn action-unbind"  value="解决绑定" /> 		 -->	
			<input type="hidden" name="doaction" id="doaction"  value="" /> 			
    </div>
     </form>
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>
<link href="/Public/static/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<link href="/Public/static/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css"><link href="/Public/static/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/Public/static/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="/Public/static/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">

	/*
	设定选择值
	*/
	$(".queryRole").val('{$Think.post.queryRole}'); 
	$(".active_type").val('{$Think.post.active_type}'); 
	$("#time-start").val('{$Think.post.time-start}');
	$("#time-end").val('{$Think.post.time-end}');
	$("#fullname").val('{$Think.post.fullname}');
	$("#telephone").val('{$Think.post.telephone}');
 
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".search-input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});
    //导航高亮
    $('.side-sub-menu').find('a[href="{:U('User/index')}"]').closest('li').addClass('current');

    /* 状态搜索子菜单 */
	$(".search-form").find(".drop-down").hover(function(){
		$("#sub-sch-menu").removeClass("hidden");
	},function(){
		$("#sub-sch-menu").addClass("hidden");
	});

	$("#sub-sch-menu li").find("a").each(function(){
		$(this).click(function(){
			var text = $(this).text();
			$("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
			$("#sub-sch-menu").addClass("hidden");
		})
	});

	$(document).on("click","#search",function(){
		_self = this;
		
	})

	//删除用户
	$(document).on("click",".action-deleuser",function(){
		_self = this;
		_url = $(_self).attr("url");

		_data =$("#thefrm").serialize();
		if (!_data) {
			alert("未选择记录");
			return false;
		}

		$.post(_url,_data,function(res){
			_o = eval("("+res+")");
			if (_o.status=="success") {
				//刷新自己
				location.reload() ;
				return false;
			} else {
				if (_o.msg) {
					alert(_o.msg);
					return false;
				}
			}
		})
	})

	$('#time-start').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
	    minView:2,
	    autoclose:true
    });

    $('#time-end').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
	    minView:2,
	    autoclose:true
    });

	$(document).on("click",".action-unbind",function(){
 
		if ($("input:checked").length==0) {
			alert("未选择记录,不能操作");
			return false;
		}
		$("#doaction").val("unbind");
		$("#AllocFrm").submit();
	})

	$(document).on("click",".action-alloc",function(){
		if ($("input:checked").length==0) {
			alert("未选择记录,不能操作");
			return false;
		}
		 
		$("#AllocFrm").submit();
	})

	$(document).on("click",".bind em",function(){

		_data = "{"+$(this).attr("item")+"}";
		_obj = eval("("+_data+")") ;
		if(!confirm("确定要清除绑定吗?")) {
			return false;
		}
		 
		_data = "bind_id="+_obj.bind_id+"&studen_id="+_obj.studen_id;
	 	_url = "{:U('user/unbind')}";
		$.ajax({
			   type: "POST",
			   url: _url,
			   data: _data,
			   success: function(data){
				_o= eval("("+data+")");
				if (_o.status=="success") {
					//刷新自己
						location.reload() ;
						return false;
					} else {
						if (_o.msg) {
							alert(_o.msg);
							return false;
						}
					}
			     
			   }
			});

	})

	 $(".reset-btn").on("click",function(){
            $('input[type=text]').val('');
            $('select').val('');

        })
	</script>
</block>
